package com.sample.order.controller;

import com.sample.order.entity.OrderTblPO;
import com.sample.order.feign.AccountFeignClient;
import com.sample.order.mapper.OrderTblMapper;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Random;
import java.util.UUID;

@RestController
public class OrderController {

    @Resource
    private OrderTblMapper orderTblMapper;

    @Resource
    private AccountFeignClient accountFeignClient;

    @GlobalTransactional
    @GetMapping("/test")
    public void test(){
        String userId = UUID.randomUUID().toString();
        OrderTblPO po = new OrderTblPO();
        po.setUserId(userId);
        orderTblMapper.insert(po);
        accountFeignClient.test(userId);
        if(new Random().nextBoolean()){
            throw new RuntimeException("----------");
        }
    }


}
